package com.acme;

import com.acme.bankapp.domain.bank.*;
import com.acme.bankapp.service.bank.BankService;

class BankApplication {
	public static void main(String[] args) {
		Bank db = new Bank();
		BankService.addClient(db, new Client(new SavingsAccount(40)));
		printBalance(db);
		BankService.addClient(db, new Client(new SavingsAccount(50)));
		printBalance(db);
		db.getClient(0);
		db.getClient(11);
		Account acc1 = new SavingsAccount(20);
		Account acc2 = new SavingsAccount(30);
		test(acc1, acc2,2);
		test(acc1, acc2,30);
		/* ======Task 2========= */
		Client clMale = new Client(new SavingsAccount(0), Gender.MALE,"Smith");
		clMale.getClientSalutation();
		Client clFemale = new Client(new SavingsAccount(0), Gender.FEMALE,"Smith");
		clFemale.getClientSalutation();
		/* ======Task 4========= */
		Account cA = new CheckingAccount(2, 88);
		System.out.println(cA.maximumAmountToWithdraw());
		Account cA2 = new CheckingAccount(2, -5);
		System.out.println(cA2.maximumAmountToWithdraw());
		Account sA = new SavingsAccount(88);
		System.out.println(sA.maximumAmountToWithdraw());
	}
	static void modifyBank(Account acc1, Account acc2, final double VAL){
		if (acc1.withdraw(VAL)){
			acc2.deposit(VAL);
		}
	}
	
	static void printBalance(Bank bank){
		for (int i = 1; i <= bank.getNumberOfClients(); i++) {
			System.out.println("Client "+i+": "+bank.getClient(i).getAccount().maximumAmountToWithdraw());
		}
		System.out.println();
	}
	static void test(Account acc1, Account acc2, double VAL){
		System.out.println(acc1.getBalance() + " " +
					acc2.getBalance() + " before changing by "+VAL);
		modifyBank(acc1, acc2, VAL);
		System.out.println(acc1.getBalance() + " " +
				acc2.getBalance() + " after");
	}
}